package com.he1618;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import org.springframework.stereotype.Service;

@Service
public class MyService {
    private final Timer myTimer;

    public MyService(MeterRegistry registry) {
        this.myTimer = Timer.builder("my.operation.timer")
            .register(registry);
    }

    public void performOperation() {
        Timer.Sample sample = Timer.start();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        // 执行业务逻辑
        sample.stop(myTimer);
    }
}
